/**
 * 
 */
package com.yidu.drug.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.drug.common.Page;
import com.yidu.drug.common.Tools;
import com.yidu.drug.model.WholesaleModel;
import com.yidu.drug.service.WholesaleService;

/**
 * 类的描述 批发订单详情action层
 * @author yuanqing
 * @date 2018年8月16日上午10:43:52
 * @version 1.0
 */
@Controller
@RequestMapping("/wholesale")
public class WholesaleAction {
	@Resource
	WholesaleService wls;
	/**
	 * 查询所有和条件查询分页
	 * @param response 响应
	 * @param me 会员对象
	 * @param page 页数
	 * @param limit 行数
	 * @return
	 */
	@RequestMapping("wholesaleFindAll")
	@ResponseBody
	public Map<String, Object> findAll(HttpServletResponse response,WholesaleModel wl,int page,int limit,String dateOne,String dateTwo) {
		
		response.setCharacterEncoding("UTF-8");
		Page pages = new Page();
		pages.setPage(page);
		pages.setRows(limit);
		Map<String,String> map=new HashMap<>();
		map.put("pfPerson", wl.getPfPerson());
		map.put("filId", "1");
		map.put("isva", wl.getIsva());
		map.put("start", String.valueOf(pages.getStart()));
		map.put("rows", String.valueOf(pages.getRows()));
		if(!Tools.isEmpty(dateOne)&&!Tools.isEmpty(dateTwo)){
			if(dateOne.compareTo(dateTwo)>0){
				map.put("dateOne", dateTwo);
				map.put("dateTwo", dateOne);
			}else{
				map.put("dateOne", dateOne);
				map.put("dateTwo", dateTwo);
			}
		}else if(!Tools.isEmpty(dateOne)&&Tools.isEmpty(dateTwo)){
			map.put("dateOne", dateOne);
		}else if(!Tools.isEmpty(dateTwo)&&Tools.isEmpty(dateOne)){
			map.put("dateTwo", dateTwo);
		}
		
		List<WholesaleModel> list = wls.findAllPage(map);
		Map<String, Object> maps = new HashMap<>();
		//需要符合layUI格式，code msg count data
		maps.put("code", 0);
		maps.put("msg", "1");
		maps.put("count", wls.findTotalRows(map));
		maps.put("data", list);
		wl=new WholesaleModel();
		
		return maps;
	}
	
	/**
	 * 审核查询所有和条件查询分页
	 * @param response 响应
	 * @param page 页数
	 * @param limit 行数
	 * @return 批发订单
	 */
	@RequestMapping("findAllCwsh")
	@ResponseBody
	public Map<String, Object> findAllCwsh(HttpServletResponse response,WholesaleModel wl,int page,int limit,String dateOne,String dateTwo) {
		
		response.setCharacterEncoding("UTF-8");
		Page pages = new Page();
		pages.setPage(page);
		pages.setRows(limit);
		Map<String,String> map=new HashMap<>();
		map.put("pfPerson", wl.getPfPerson());
		map.put("filId", "1");
		map.put("isva", "1");
		map.put("start", String.valueOf(pages.getStart()));
		map.put("rows", String.valueOf(pages.getRows()));
		if(!Tools.isEmpty(dateOne)&&!Tools.isEmpty(dateTwo)){
			if(dateOne.compareTo(dateTwo)>0){
				map.put("dateOne", dateTwo);
				map.put("dateTwo", dateOne);
			}else{
				map.put("dateOne", dateOne);
				map.put("dateTwo", dateTwo);
			}
		}else if(!Tools.isEmpty(dateOne)&&Tools.isEmpty(dateTwo)){
			map.put("dateOne", dateOne);
		}else if(!Tools.isEmpty(dateTwo)&&Tools.isEmpty(dateOne)){
			map.put("dateTwo", dateTwo);
		}
		
		List<WholesaleModel> list = wls.findAllPage(map);
		Map<String, Object> maps = new HashMap<>();
		//需要符合layUI格式，code msg count data
		maps.put("code", 0);
		maps.put("msg", "1");
		maps.put("count", wls.findTotalRows(map));
		maps.put("data", list);
		wl=new WholesaleModel();
		
		return maps;
	}
	/**
	 * 删除批发订单的方法
	 * @param pfId 批发Id
	 * @return 是否成功
	 */
	@RequestMapping("deleteWholesale")
	@ResponseBody
	public String deleteWholesale(String pfId){
		int row=wls.deleteByPrimaryKey(pfId);
		if(row>0){
			return "ok";
		}else{
			return "no";
		}
		
	}

}
